package cn.huiyunche.admin.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.huiyunche.base.service.interfaces.SServiceOrderService;
import cn.huiyunche.base.service.utils.DateUtils;
import cn.huiyunche.base.service.vo.PageVo;
import cn.huiyunche.base.service.vo.Result;
import cn.huiyunche.base.service.vo.SServiceOrderAdminVo;

/**
 * 服务订单Controller
 * 
 * @author Administrator
 *
 */
@RequestMapping("/serviceorder")
@Controller
public class SServiceOrderController {

	private static final Logger logger = LoggerFactory.getLogger(SServiceOrderController.class);

	@Autowired
	private SServiceOrderService sServiceOrderService = null;

	public SServiceOrderService getSServiceOrderService() {
		return this.sServiceOrderService;
	}

	/**
	 * 查询服务订单列表
	 * 
	 * @param page
	 * @param sServiceOrderVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public Result<Map<String, Object>> list(PageVo page, SServiceOrderAdminVo sServiceOrderVo) {
		Result<Map<String, Object>> result = new Result<Map<String, Object>>(true, null, "数据加载成功");
		logger.info("select service order params : {}.", JSON.toJSONString(sServiceOrderVo));
		sServiceOrderVo.setIsVeneer(false);
		result.setData(this.getSServiceOrderService().list(page, sServiceOrderVo));
		return result;
	}

	/**
	 * 更新服务订单状态
	 * 
	 * @param id
	 * @param status
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/updateservicestatus", method = RequestMethod.POST)
	public Result<Object> updateServiceStatus(String ids, String status) throws Exception {
		logger.info("updateServiceStatus params : id: {}, status: {}", ids, status);
		Result<Object> result = new Result<Object>(true, null, "服务调度状态更新成功");
		result.setData(this.getSServiceOrderService().updateServiceStatus(ids, status));
		return result;
	}
	
	
	/**
	 * 语音提示
	 * 
	 * @param date 开始时间
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/voice", method = RequestMethod.GET)
	public Result<String> selectAfterByParams(String date) throws Exception {
		logger.info("selectAfterByParams params : {}", date);
		Result<String> result = new Result<>(true, null, "服务调度状态更新成功");
		result.setSuccess(this.getSServiceOrderService().selectAfterByParams(DateUtils.StrToDate(date, "yyyy-MM-dd HH:mm")) > 0);
		return result;
	}

}
